/*
 * @Author: wangyingjie 2778809626@qq.com
 * @Date: 2025-04-16 14:12:51
 * @LastEditors: wangyingjie 2778809626@qq.com
 * @LastEditTime: 2025-04-17 16:29:53
 * @FilePath: /ros2_proj_template/src/publish_pkg/core/config/module_a_config.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

#ifndef MODULE_A_CONFIG_H
#define MODULE_A_CONFIG_H

#include "project_marco.h"

/// <summary>/// 配置模块A
/// </summary>
class module_a_config :public studio_singleton<module_a_config>
{

public:
	std::string name;
	int age;
	double height;
	bool is_student;
	std::vector<std::string> hobbies;
	std::map<std::string, std::string> address;
public:
	bool read_config(const std::string& path)
	{
		bool status = false;
		if(!std::filesystem::exists(path))
		{
			std::cout << "config ile is not exist:" << path << std::endl;
			return status;
		}
                Json::Value root = studio_json::loadf(path);
		if(root.isNull())
		{
			return true;
		}
		if(!studio_json::check_str(root, "name",name))
		{
			std::cout << "read config error, name is not exist" << std::endl;
			return status;
		}
		if(!studio_json::check_int32(root, "age",age))
		{
			std::cout << "read config error, age is not exist" << std::endl;
			return status;
		}	
		if(!studio_json::check_double(root, "height",height))
		{
			std::cout << "read config error, height is not exist" << std::endl;
			return status;
		}
		if(!studio_json::check_bool(root, "is_student",is_student))
		{
			std::cout << "read config error, is_student is not exist" << std::endl;
			return status;
		}
		Json::Value hobbies_json;
		if(!studio_json::check_arr(root, "hobbies",hobbies_json))
		{
			std::cout << "read config error, hobbies is not exist" << std::endl;
			return status;
		}
		for(const auto& hobby : hobbies_json)
		{
			if(!hobby.isString())
			{
				std::cout << "read config error, hobby is not string" << std::endl;
				return status;
			}
			hobbies.push_back(hobby.asString());
		}
		Json::Value address_json;
		if(!studio_json::check_obj(root, "address",address_json))
		{
			std::cout << "read config error, address is not exist" << std::endl;
			return status;
		}
		if(!address_json.isObject())
		{
			std::cout << "read config error, address is not object" << std::endl;
			return status;
		}
		if(!studio_json::check_str(address_json, "city",address["city"]))
		{
			std::cout << "read config error, city is not exist" << std::endl;
			return status;
		}
		if(!studio_json::check_str(address_json, "street",address["street"]))
		{
			std::cout << "read config error, street is not exist" << std::endl;
			return status;
		}
		status = true;
		return true;
	}
};


#endif //MODULE_A_CONFIG_H
